package com.starlight.easybuyprictice.controller;

import com.starlight.easybuyprictice.interceptor.FreeTokenAuthentication;
import com.starlight.easybuyprictice.service.MemberManageService;
import com.starlight.easybuyprictice.service.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;



/**
 * @Author yfy2001
 * @date 2022/11/28 21:12
 */
@Controller
@RequestMapping("member")
public class MemberController {


    private final MemberManageService memberManageService;

    public MemberController(MemberManageService memberManageService) {
        this.memberManageService = memberManageService;
    }

    @PostMapping("/login")
    @ResponseBody
    @FreeTokenAuthentication
    public Result login(String uname, String password) {
        System.out.println("User:"+uname);
        return memberManageService.login(uname, password);
    }

    @PostMapping("/register")
    @ResponseBody
    @FreeTokenAuthentication
    public Result register(String uname, String password) {
        return memberManageService.register(uname, password);
    }

    @PostMapping("/logout")
    @ResponseBody
    @FreeTokenAuthentication
    public Result logout(String tokenValue) {
        return memberManageService.logout(tokenValue);
    }

    /**
     * 后台获取用户列表
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    @FreeTokenAuthentication
    public Result listMember(){
        return  memberManageService.listMember();
    }


}


